#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/6/10 10:53
# @Author  : fuchen'en
# @Description:

import pika

credentials = pika.PlainCredentials('test', 'test123')
parameters = pika.ConnectionParameters(host='10.0.20.66',
                                       port='5672',
                                       virtual_host='/',
                                       credentials=credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
# 创建队列
channel.queue_declare('hello')

# 消息不能直接发送到队列，需要交换机（exchange）来进行，这里我们采用空字符表示的默认交换机
channel.basic_publish('', 'hello', 'hello world!')
print(' [x] send "hello world!"')

# 在退出之前，我们需要确认网络缓存已经被刷新、消息已经投递到RabbitMQ。通过安全关闭连接可以做到这一点
connection.close()
